/*
 * $Id$
 */
package com.ptdworld.ratking;

import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;

/**
 *
 * @author user
 */
public class IconFileProcess {

    /** 用OfflineExplorer下载的PrimeFaces的保存路径 */
    public final static String FONT_ICONS = "D:\\OfflineExplorerPortable\\Download\\www.primefaces.org\\volt\\font-icons.xhtml";

    /**
     * @param args the command line arguments
     * @throws java.io.IOException
     */
    public static void main(String[] args) throws IOException {
        BufferedReader br = new BufferedReader(new InputStreamReader(new FileInputStream(FONT_ICONS), "UTF-8"));
        BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(FONT_ICONS + "-new"), "UTF-8"));
        boolean findIcon = false;
        boolean findIconName = false;
        String iconName = null;
        String line = null;
        while ((line = br.readLine()) != null) {
            if (findIcon) {
                if (findIconName) {
                    if (line.trim().length() == 0) {
                        continue;
                    }
                    if (line.contains("<span class=\"muted\">")) {
                        findIcon = false;
                        findIconName = false;
                    }
                    bw.write(line);
                    bw.newLine();
                } else {
                    if (line.trim().length() == 0) {
                        continue;
                    }
                    iconName = line.trim();
                    findIconName = true;
                    String s = "                                  <i class=\"fa fa-fw " + iconName + "\"/>";
                    bw.write(s);
                    bw.newLine();
                    bw.write(line);
                    bw.newLine();
                }
            } else if (line.contains("<i class=\"fa fa-fw\">")) {
                findIcon = true;
            } else {
                bw.write(line);
                bw.newLine();
            }
        }
    }
}
